package com.medicalfee.dao;

import java.util.List;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class ReimbursementListDAO extends HibernateDaoSupport {
	public void InsertReimbursement(ReimbursementList reimbursement) {
		this.getHibernateTemplate().save(reimbursement);
	}

	public void deleteReimbursement(String ids[]) {
		for (int i = 0; i < ids.length; i++) {
			this.getHibernateTemplate().delete(
					this.getHibernateTemplate()
							.find("from ReimbursementList where id=" + ids[i])
							.get(0));
		}
	}

	public List getReimbursementList(String hql, int startPage, int limitNum) {
		Session session = this.getSession();
		session.getTransaction().begin();
		List result = session.createQuery(hql)
				.setFirstResult((startPage - 1) * limitNum)
				.setMaxResults(limitNum).list();
		session.getTransaction().commit();
		session.close();
		return result;
	}

	public void updateReimbursement(ReimbursementList reimbursement) {
		this.getHibernateTemplate().saveOrUpdate(reimbursement);
	}

	public List findReimbursements(String value, String object, int startPage,
			int limitNum) {
		Session session = this.getSession();
		session.getTransaction().begin();
		List result = session
				.createQuery(
						"from ReimbursementList where " + object + " like ?")
				.setString(0, "%" + value + "%")
				.setFirstResult((startPage - 1) * limitNum)
				.setMaxResults(limitNum).list();
		session.getTransaction().commit();
		session.close();
		return result;
	}
}
